package cn.laixueit.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@Controller
@RequestMapping("/student")
@SessionAttributes("msg")
public class StudentController {

    @RequestMapping("/getbyid/{id}")
    @ResponseBody
    public String getById(@PathVariable String id){
        System.out.println(id);
        return id;
    }

    @RequestMapping("/get/{name}/{id}")
    public String get(@PathVariable String name,@PathVariable String id){
        return name+id;
    }

    @RequestMapping("/to/{dir}/{pagename}")
    public String to(@PathVariable(value = "dir")  String dirname, @PathVariable String pagename){
        return dirname+"/"+pagename;
    }

    @RequestMapping("/to/{dir}")
    public String s(@PathVariable String dir,String name){
        System.out.println(dir+name);
        return "student/a";
    }

    @RequestMapping("/gethead")
    public @ResponseBody String gethead(@RequestHeader("Accept")String accept,@RequestHeader("Host")String host){
        System.out.println(accept+host);
        return accept+host;
    }


    @RequestMapping("/getsessionid")
    public @ResponseBody String getsessionid(@CookieValue("JSESSIONID")String accept ,@CookieValue("Webstorm-88240b9d")String cook){
        System.out.println(accept);
        return accept+"---"+cook;
    }


    @ModelAttribute
    public void show(HashMap map){
        System.out.println("show...");
        map.put("msg","hello");
    }


    @RequestMapping("/testmodelatt")
    public String testmodelatt(@ModelAttribute("msg") String msg){
        System.out.println(msg);
        return "asd";
    }


    @RequestMapping("/testgetsession")
    public String testgetsession(ModelMap modelMap){
        System.out.println(modelMap.get("msg"));
        return "as";
    }
}
